﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Skyhook.Sprites
{
    internal class SpritePartialRenderer : ISpriteRenderer
    {
        double X, Y;
        double Width, Height;
        public SpritePartialRenderer(double x, double y, double width, double height)
        {
            X = x;
            Y = y;
            Width = width;
            Height = height;
        }
        public void Render(SpriteBatch batch, Sprite sprite, Point position, Color color, float depth)
        {
            Vector2 vposition = new Vector2(position.X, position.Y);
            double w = sprite.TextureRectangle.Width;
            double h = sprite.TextureRectangle.Height;
            Rectangle texturerect = new Rectangle((int)(sprite.TextureRectangle.X + w * X),(int)(sprite.TextureRectangle.Y + h * Y),(int)(Width * w),(int)(Height * h));
            Vector2 centerpoint = new Vector2((float)(sprite.CenterPoint.X - w * X),(float)(sprite.CenterPoint.Y - h * Y));
            batch.Draw(sprite.Texture, vposition - centerpoint, texturerect, color, 0, new Vector2(0, 0), 1.0f, SpriteEffects.None, depth); 
        }
    }
}
